package cn.com.xyc.common;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtils {
	private static Configuration config;
	private static SessionFactory factory;

	/*
	 * config对象只要加载一次就可以了 如果放入openSession方法中效率会降低
	 */
	static {
		config = new Configuration();
		config.configure();
		factory = config.buildSessionFactory();
	}

	/*
	 * 每个用户会对应一个	Session,但是 SessionFactory是共享的
	 */
	public static Session openSession() {
		return factory.openSession();
	}
}
